package com.paradogs.gs.misc;

import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.gitee.sunchenbin.mybatis.actable.annotation.DefaultValue;
import com.gitee.sunchenbin.mybatis.actable.annotation.Unique;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * @author: yumi
 * @date: 2023/11/20  11:01
 * @Description: 多实例 DB 对象，不设置主键，使用唯一复合索引 uid、id
 */
@Data
@ProtobufClass
public class BaseMgrMultiEntity {

    // 玩家 ID
    @Protobuf(order = 1)
    @Unique(columns = {"uid", "id"})
    @TableField(value = "uid")
    private Long uid;

    // 唯一 ID
    @Protobuf(order = 2)
    @TableField(value = "id")
    private Long id;

    // 创建时间
    @Protobuf(order = 3)
    @DefaultValue("CURRENT_TIMESTAMP")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    // 更新时间
    @Protobuf(order = 4)
    @DefaultValue("NULL ON UPDATE CURRENT_TIMESTAMP")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /** aid 生成策略自定义, 默认可以实现 IdWorker.getId() */
    public BaseMgrMultiEntity(Long id) {
        this.id = id;
    }
    public BaseMgrMultiEntity() {
        this.id = IdWorker.getId();
    }

}
